package cn.baage.campus.utils;
import com.github.pagehelper.PageHelper;


/**
 * @Description: 分页工具
 * @Author: 八阿哥
 * @url: baage.cn
 * @Version: 1.0
 **/
public class PageUtils extends PageHelper
{
    /**
     * 设置请求分页数据
     */
    public static void startPage() {
        PageDomain pageDomain = PageBuild.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = getPageSize(pageDomain.getPageSize());
        String orderBy = SqlUtils.escapeOrderBySql(pageDomain.getOrderBy());
        Boolean reasonable = pageDomain.getReasonable();
        PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
    }

    /**
     * 清理分页的线程变量
     */
    public static void clearPage()
    {
        PageHelper.clearPage();
    }


    private static Integer getPageSize(Integer pageSize) {
        if (pageSize == null || pageSize < 1) {
            return 10;
        }
        if (pageSize > 100) {
            return 100;
        }
        return pageSize;
    }

}
